﻿using System;
using System.Web.UI;
using System.Web.UI.HtmlControls;

namespace JQuery.WebKit
{
    public class MessageBox : AeroWindow
    {
        private string _message;

        public string Title
        {
            get { return base.WindowTitle; }
            set { base.WindowTitle = value; }
        }

        public MessageBox()
        {
            base.DeferLoad = false;
            base.AutoOpen = false;
        }

        //protected override void CreateChildControls()
        //{
        //    base.CreateChildControls();
        //}

        public void Show(string message)
        {
            _message = message;
        }

        protected override void OnPreRender(EventArgs e)
        {
            if (!string.IsNullOrEmpty(_message))
            {
                this.Controls.Add(new LiteralControl(string.Format("<span>{0}</span>", _message)));
                this.Controls.Add(new LiteralControl("<hr />"));
                HtmlInputButton btnOk = new HtmlInputButton();
                btnOk.Value = "Ok";
                btnOk.Attributes.Add("onclick", string.Format("\"$('#{0}').AeroWindow('hide')\"", this.ClientID));
                this.Controls.Add(btnOk);
            }
            base.OnPreRender(e);

        }

        protected override void Render(HtmlTextWriter writer)
        {
            base.Render(writer);
            _message = string.Empty;
        }
    }
}
